<template>
	<view class="black">
		<view class="fixed">
			<cu-custom :isBack="true" bgColor="bg-shadeTop text-white">
				<block slot="backText">返回</block>
				<!-- <block slot="content">电影预告</block> -->
			</cu-custom>
		</view>
		
		<image 
			class="poster" 
			:src="poster"
			mode="widthFix"
			@longpress="operator">
		</image>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				poster: ''
			}
		},
		onLoad(params) {
			var poster = params.poster;
			this.poster = poster;
		},
		methods: {
			operator() {
				var me = this;
				uni.showActionSheet({
					itemList: ['保存图片到本地'],
					success: (res) => {
						// 0 - 下载图片
						if(res.tapIndex == 0) {
							uni.showLoading({
								title: '正在保存图片...'
							});
							uni.downloadFile({
								url: me.poster,
								success: (result) => {
									var tempFilePath = result.tempFilePath;
									// console.log(tempFilePath);
									uni.saveImageToPhotosAlbum({
										filePath: tempFilePath,
										success: () => {
											uni.showToast({
												title: '保存成功',
												duration: 2000
											});
										},
										complete: () => {
											uni.hideLoading();
										}
									})
								}
							});
						}
					}
				});
			}
		}
	}
</script>

<style>
.black {
	display: flex;
	flex-direction: column;
	justify-content: center;
	position: fixed;
	width: 100%;
	height: 100%;
	background-color: #000;
}

.poster {
	align-self: center;
}
</style>
